package org.example.创建型模式.工厂方法模式.重构代码.发奖服务场景_工厂方法.store.impl;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.example.创建型模式.工厂方法模式.基层.发奖服务场景_工厂方法.coupon.CouponResult;
import org.example.创建型模式.工厂方法模式.基层.发奖服务场景_工厂方法.coupon.CouponService;
import org.example.创建型模式.工厂方法模式.重构代码.发奖服务场景_工厂方法.store.ICommodity;

import java.util.Map;

/**
 * TODO
 * 优惠券
 * @author: hmxchen
 * @date : 2022/4/11 20:22
 */
@Slf4j
public class CouponCommodityService implements ICommodity {

    private CouponService couponService = new CouponService();

    public void sendCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) {
        CouponResult couponResult = couponService.sendCoupon(uId, commodityId, bizId);
        log.info("请求参数[优惠券] => uId：{} commodityId：{} bizId：{} extMap：{}", uId, commodityId, bizId, JSONUtil.toJsonStr(extMap));
        log.info("测试结果[优惠券]：{}", JSONUtil.toJsonStr(couponResult));
        if (!"0000".equals(couponResult.getCode())) {
            throw new RuntimeException(couponResult.getInfo());
        }
    }

}
